var mobid;
var mob;
var modified;
var MaxRandom;
var setupTask;
var MapList = Array(
	450004150, //梦幻森林 挑战露西德
	450004550,
	450004500
);
var moblevel = 250;
var smallMobHp = 1000000000;
var bossHp = 30000000000000;

function init() {
	em.setProperty("state", "0");
}

function setup(level, leaderid) {
	level = moblevel;
	var eim = em.newInstance("BossLucid_HARD");
	for (var i = 0; i < MapList.length; i++) {
		var map = eim.setInstanceMap(MapList[i]);
		map.resetPQ(level);
		map.resetFully();
		map.killAllMonsters(true);
	}
	em.setProperty("state", "1");
	//梦幻森林 

	mobid = 8880184; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(805, 48));


	mobid = 8880140; //梦中露西德
	mob = em.getMonster(mobid);
	var MobLu = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(bossHp);
	modified.setOMp(mob.getMobMaxMp() * 2);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(999, 43));

	mobid = 8880184; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(1030, 48));

	mobid = 8880184; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(925, 48));

	mobid = 8880184; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(797, 48));

	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(346, 48));

	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(1341, 48));

	mobid = 8880184; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(374, 48));

	mobid = 8880184; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(1648, 48));


	mobid = 8880166; //露西德之花
	mob = em.getMonster(mobid);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(999, 43));

	mobid = 8880164; //噩梦蘑菇
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	modified.setOMp(mob.getMobMaxMp() * 2);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(608, 43));

	mobid = 8880164; //噩梦蘑菇
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	modified.setOMp(mob.getMobMaxMp() * 2);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004150);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(1428, 43));

	mobid = 8880167; //最后的音乐盒
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(888888888);
	//modified.setOMp(mob.getMobMaxMp() * 2);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004500);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(73, 36));


	mobid = 8880150; //露西德
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(bossHp * 2);
	modified.setOMp(mob.getMobMaxMp() * 2);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(657, -490));


	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(122, -550));

	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(122, -550));


	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(537, -685));

	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(1211, -378));


	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(786, -194));

	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(329, -125));

	mobid = 8880160; //噩梦石头人
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(smallMobHp);
	mob.setOverrideStats(modified);
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(450004550);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(117, -267));



	setupTask=eim.startEventTimer(1000 * 60 * 60); // 60分钟 
	return eim;
}

function playerEntry(eim, player) {
	for (var i = 0; i < eim.getPlayerCount(); i++) {}
	if (i <= 1) {
		eim.setProperty("Name", "露西德");
		eim.setProperty("PlayerName", eim.getPlayers().get(0).getName());
	}
	var map = eim.getMapInstance(0);
	player.restReviveCount();
	player.setReviveCount(5);
	player.dropMessage(6, "[露西德] 进入到了挑战地图，请小心行事。");
	player.changeMap(map, map.getPortal(0));
}

function scheduledTimeout(eim) {
	// eim.broadcastPlayerMsg(1, "[露西德] 真遗憾！已超过限定挑战时间，本次挑战失败！别气馁，期待更加强大的您前来挑战~");
	eim.disposeIfPlayerBelow(100, 450004000);
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}


function playerDead(eim, player) {
	if (player.getReviveCount() < 1) {
		var map = eim.getMapInstance(450004000);
		player.changeMap(map, map.getPortal(0));
	}
}

function playerRevive(eim, player) {
	return false;
}

function playerExit(eim, player) {
	em.setProperty("state", "0");
	setupTask.cancel(true);
	eim.disposeIfPlayerBelow(100, 450004000);
}

function playerDisconnected(eim, player) {
	eim.unregisterPlayer(player);
	return 0;
}


function openNpc(eim, npcid, mode) {
	for (var i = 0; i < eim.getPlayerCount(); i++) {
		eim.getPlayers().get(i).openNpc(npcid, mode);
	}
}

function monsterValue(eim, mobid) {
	if (mobid == 8880140) { //露西德第二阶段
		eim.getMapFactory().getMap(450004150).killAllMonsters(true); //杀死所有怪物
		setupTask = em.schedule("chuansong", 1000 * 1 * 3, eim); //延迟3秒过图
		return 0;
	}
	if (mobid == 8880150) {
		eim.getMapFactory().getMap(450004550).killAllMonsters(true); //杀死所有怪物
		setupTask = em.schedule("chuansongk", 1000 * 1 * 3, eim); //延迟3秒召唤NPC
		return 0;
	}
	if (mobid == 8880167) {
		var map = eim.getMapInstance(450004500);
		eim.startEventTimer(1000 * 60 * 2); // 60分钟 
		map.startMapEffect("恭喜挑战露西德成功，将在2分钟后传送出去！", 5120161);
		setupTask = em.schedule("chuansongo", 1000 * 1 * 120, eim);
		return 0;
	}
	return 1;
}

function chuansong(eim, player) {
	if (eim.getMapFactory().getMap(450004150).getCharactersSize() != 0) {
		openNpc(eim, 0, "LucidDeath"); //monsterdrop 不能使用于地图原有的怪物，只能这样了T.T
	}
}

function chuansongk(eim, player) {
	if (eim.getMapFactory().getMap(450004550).getCharactersSize() != 0) {
		var map = eim.getMapInstance(450004550);
		openNpc(eim, 0, "LucidDeath"); //monsterdrop 不能使用于地图原有的怪物，只能这样了T.T
	}
}

function chuansongo(eim, player) {
	if (eim.getMapFactory().getMap(450004500).getCharactersSize() != 0) {
		var map = eim.getMapInstance(450004500);
		openNpc(eim, 0, "LucidDeath"); //monsterdrop 不能使用于地图原有的怪物，只能这样了T.T
	}
}

function monsterKilled(eim, player, cp) {}

function allMonstersDead(eim) {}

function openNpc(eim, npcid, mode) {
	for (var i = 0; i < eim.getPlayerCount(); i++) {
		eim.getPlayers().get(i).openNpc(npcid, mode);
	}
}

function monsterDamaged(eim, player, mobid, damage) {}

function cancelSchedule() {
	if (setupTask != null)
		setupTask.cancel(true);
}

function leftParty(eim, player) {
	eim.disposeIfPlayerBelow(100, 450004000);
}

function disbandParty(eim) {
	eim.disposeIfPlayerBelow(100, 450004000);
}

function onMapLoad(eim, player) {}

function monsterDrop(eim, player, mob) {}

function monsterKilled(eim, player, mobID) {
	// 可留空，主要处理怪物死亡后的逻辑代码
}